package com.liujun.spring4x.demo.dao;

import com.liujun.spring4x.demo.domain.LoginLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * 进行用户管理操作日志记录
 *
 * @author liujun
 * @version 1.0
 * @date 2018-08-05 13:05:00
 */
@Repository
public class LoginLogDaoImpl implements LoginLogDao {

  private JdbcTemplate jdbcTemplate;

  /** 进行插入SQL操作的SQL */
  private static final String INSERT_LOGIN_LOG_SQL =
      "insert into t_login_log(user_id,ip,login_datetime)  values(?,?,?)";

  /**
   * 进行数据库的日志插入
   *
   * @param loginLog 日志信息
   */
  @Override
  public void insertLoginLog(LoginLog loginLog) {
    Object[] args = {loginLog.getUserId(), loginLog.getIp(), loginLog.getLoginDate()};
    this.jdbcTemplate.update(INSERT_LOGIN_LOG_SQL, args);
  }

  @Autowired
  public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
  }
}
